<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-hemisu.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-hemisu.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-hemisu.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="hemisu">










<meta name="description" content="Just do...">
<meta name="keywords" content="web, 前端, 生活, 分享">
<meta property="og:type" content="website">
<meta property="og:title" content="何米酥`s Blog">
<meta property="og:url" content="http://www.hemisu.com/page/15/index.html">
<meta property="og:site_name" content="何米酥`s Blog">
<meta property="og:description" content="Just do...">
<meta property="og:locale" content="zh-Hans">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="何米酥`s Blog">
<meta name="twitter:description" content="Just do...">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":true,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://www.hemisu.com/page/15/">





  <title>何米酥`s Blog</title>
  








  <!-- Hotjar Tracking Code for www.hemisu.com -->
  <script>
      (function(h,o,t,j,a,r){
          h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
          h._hjSettings={hjid:1933736,hjsv:6};
          a=o.getElementsByTagName('head')[0];
          r=o.createElement('script');r.async=1;
          r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
          a.appendChild(r);
      })(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');
  </script>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left 
  page-home">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">何米酥`s Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">EFE</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
  <section id="posts" class="posts-expand">
    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.hemisu.com/2017/02/09/113/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="何米酥">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="何米酥`s Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/02/09/113/" itemprop="url">PAT A1028</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-02-09T15:17:53+00:00">
                2017-02-09
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/algorithm-PAT/" itemprop="url" rel="index">
                    <span itemprop="name">algorithm - PAT</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>Excel can sort records according to any column. Now you are supposed to imitate this function.</p>
<p>Input</p>
<p>Each input file contains one test case. For each case, the first line contains two integers N (&lt;=100000) and C, where N is the number of records and C is the column that you are supposed to sort the records with. Then N lines follow, each contains a record of a student. A student’s record consists of his or her distinct ID (a 6-digit number), name (a string with no more than 8 characters without space), and grade (an integer between 0 and 100, inclusive).</p>
<p>Output</p>
<p>For each test case, output the sorting result in N lines. That is, if C = 1 then the records must be sorted in increasing order according to ID’s; if C = 2 then the records must be sorted in non-decreasing order according to names; and if C = 3 then the records must be sorted in non-decreasing order according to grades. If there are several students who have the same name or grade, they must be sorted according to their ID’s in increasing order.</p>
<p>Sample Input 1<br>3 1<br>000007 James 85<br>000010 Amy 90<br>000001 Zoe 60<br>Sample Output 1<br>000001 Zoe 60<br>000007 James 85<br>000010 Amy 90<br>Sample Input 2<br>4 2<br>000007 James 85<br>000010 Amy 90<br>000001 Zoe 60<br>000002 James 98<br>Sample Output 2<br>000010 Amy 90<br>000002 James 98<br>000007 James 85<br>000001 Zoe 60<br>Sample Input 3<br>4 3<br>000007 James 85<br>000010 Amy 90<br>000001 Zoe 60<br>000002 James 90<br>Sample Output 3<br>000001 Zoe 60<br>000007 James 85<br>000002 James 90<br>000010 Amy 90</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><span class="line">#include &quot;stdio.h&quot;</span><br><span class="line">//#include &quot;math.h&quot;</span><br><span class="line">#include &quot;string.h&quot;</span><br><span class="line">#include &quot;algorithm&quot;</span><br><span class="line">using namespace std;</span><br><span class="line">struct person&#123;</span><br><span class="line">    char id[10];</span><br><span class="line">    char name[10];</span><br><span class="line">    int score;</span><br><span class="line">&#125;stu[100010],temp;</span><br><span class="line">bool cmpbyid(person a, person b)&#123;</span><br><span class="line">    return strcmp(a.id, b.id) &lt; 0;</span><br><span class="line">&#125;</span><br><span class="line">bool cmpbyname(person a, person b)&#123;</span><br><span class="line">    if (strcmp(a.name, b.name) != 0) &#123;</span><br><span class="line">        return strcmp(a.name, b.name) &lt; 0;</span><br><span class="line">    &#125;else&#123;</span><br><span class="line">        return strcmp(a.id, b.id) &lt; 0;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">bool cmpbyscore(person a, person b)&#123;</span><br><span class="line">    if (a.score != b.score) &#123;</span><br><span class="line">        return a.score &lt; b.score;</span><br><span class="line">    &#125;else&#123;</span><br><span class="line">        return strcmp(a.id, b.id) &lt; 0;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">int main()&#123;</span><br><span class="line">    int n, c;</span><br><span class="line">    scanf(&quot;%d%d&quot;, &amp;n, &amp;c);</span><br><span class="line">    for (int i = 0 ; i &lt; n ; i++) &#123;</span><br><span class="line">        scanf(&quot;%s%s%d&quot;, stu[i].id, stu[i].name, &amp;stu[i].score);</span><br><span class="line">    &#125;</span><br><span class="line">    if (c == 1) &#123;</span><br><span class="line">        sort(stu, stu + n , cmpbyid);</span><br><span class="line">    &#125;else if (c ==2)&#123;</span><br><span class="line">        sort(stu, stu + n , cmpbyname);</span><br><span class="line">    &#125;else&#123;</span><br><span class="line">        sort(stu, stu + n , cmpbyscore);</span><br><span class="line">    &#125;</span><br><span class="line">    for (int i = 0 ; i &lt; n ; i++) &#123;</span><br><span class="line">        printf(&quot;%s %s %d\n&quot;, stu[i].id, stu[i].name, stu[i].score);</span><br><span class="line">    &#125;</span><br><span class="line">    return 0;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.hemisu.com/2017/02/08/110/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="何米酥">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="何米酥`s Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/02/08/110/" itemprop="url">PAT A1025</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-02-08T16:28:08+00:00">
                2017-02-08
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/algorithm-PAT/" itemprop="url" rel="index">
                    <span itemprop="name">algorithm - PAT</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately after the test. Now it is your job to write a program to correctly merge all the ranklists and generate the final rank.</p>
<p>Input Specification:</p>
<p>Each input file contains one test case. For each case, the first line contains a positive number N (&lt;=100), the number of test locations. Then N ranklists follow, each starts with a line containing a positive integer K (&lt;=300), the number of testees, and then K lines containing the registration number (a 13-digit number) and the total score of each testee. All the numbers in a line are separated by a space.</p>
<p>Output Specification:</p>
<p>For each test case, first print in one line the total number of testees. Then print the final ranklist in the following format:</p>
<p>registration_number final_rank location_number local_rank</p>
<p>The locations are numbered from 1 to N. The output must be sorted in nondecreasing order of the final ranks. The testees with the same score must have the same rank, and the output must be sorted in nondecreasing order of their registration numbers.</p>
<p>Sample Input:<br>2<br>5<br>1234567890001 95<br>1234567890005 100<br>1234567890003 95<br>1234567890002 77<br>1234567890004 85<br>4<br>1234567890013 65<br>1234567890011 25<br>1234567890014 100<br>1234567890012 85<br>Sample Output:<br>9<br>1234567890005 1 1 1<br>1234567890014 1 2 1<br>1234567890001 3 1 2<br>1234567890003 3 1 2<br>1234567890004 5 1 4<br>1234567890012 5 2 2<br>1234567890002 7 1 5<br>1234567890013 8 2 3<br>1234567890011 9 2 4</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><span class="line">#include &quot;stdio.h&quot;</span><br><span class="line">//#include &quot;math.h&quot;</span><br><span class="line">#include &quot;string.h&quot;</span><br><span class="line">#include &quot;algorithm&quot;</span><br><span class="line">using namespace std;</span><br><span class="line">struct person&#123;</span><br><span class="line">    char id[15];</span><br><span class="line">    int score;</span><br><span class="line">    int location;</span><br><span class="line">    int final_rank;</span><br><span class="line">    int local_rank;</span><br><span class="line">&#125;stu[3010],temp;</span><br><span class="line">bool cmp(person a, person b)&#123;</span><br><span class="line">    return a.score &gt; b.score;</span><br><span class="line">&#125;</span><br><span class="line">int main()&#123;</span><br><span class="line">    int location, n, total = 0;</span><br><span class="line">    scanf(&quot;%d&quot;, &amp;location);</span><br><span class="line">    for (int i = 1; i &lt;= location; i++) &#123;</span><br><span class="line">        scanf(&quot;%d&quot;, &amp;n);</span><br><span class="line">        for (int j = 0; j &lt; n; j++) &#123;</span><br><span class="line">            scanf(&quot;%s%d&quot;, stu[total].id, &amp;stu[total].score);</span><br><span class="line">            stu[total].location = i;</span><br><span class="line">            total++;</span><br><span class="line">        &#125;</span><br><span class="line">        //先按各场地成绩排名</span><br><span class="line">        sort(stu + total - n, stu + total, cmp);</span><br><span class="line">        stu[total - n].local_rank = 1;//确认第一名</span><br><span class="line">        for (int i = 1; i &lt;= n; i++) &#123;</span><br><span class="line">            if (stu[total - n + i].score == stu[total - n + i - 1].score) stu[total - n +i].local_rank = stu[total - n + i - 1].local_rank;</span><br><span class="line">            else stu[total - n + i].local_rank = i + 1;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    //再按成绩排名</span><br><span class="line">    sort(stu, stu + total, cmp);</span><br><span class="line">    stu[0].final_rank = 1;//确认第一名</span><br><span class="line">    for (int i = 1; i &lt;= total; i++) &#123;</span><br><span class="line">        if (stu[i].score == stu[i - 1].score) stu[i].final_rank = stu[i - 1].final_rank;</span><br><span class="line">        else stu[i].final_rank = i + 1;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    printf(&quot;%d\n&quot;, total);</span><br><span class="line">    for (int i = 0; i &lt; total; i++) &#123;</span><br><span class="line">        printf(&quot;%s %d %d %d\n&quot;, stu[i].id, stu[i].final_rank, stu[i].location, stu[i].local_rank);</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    return 0;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>自己敲的<br>测试点    结果    用时(ms)    内存(kB)    得分/满分<br>0    答案正确    3    384    13/13<br>1    答案错误    4    384    0/6<br>2    答案正确    3    384    3/3<br>3    段错误    5    432    0/3</p>
<p>将cmp函数修改成以下后，1测试点答案正确<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">bool cmp(person a, person b)&#123;</span><br><span class="line">    if(a.score != b.score) return a.score &gt; b.score;</span><br><span class="line">    else return strcmp(a.id, b.id) &lt; 0;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>最后定义成stu[30010]解决段错误，AC<br>最后代码如下：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br></pre></td><td class="code"><pre><span class="line">#include &quot;stdio.h&quot;</span><br><span class="line">//#include &quot;math.h&quot;</span><br><span class="line">#include &quot;string.h&quot;</span><br><span class="line">#include &quot;algorithm&quot;</span><br><span class="line">using namespace std;</span><br><span class="line">struct person&#123;</span><br><span class="line">    char id[15];</span><br><span class="line">    int score;</span><br><span class="line">    int location;</span><br><span class="line">    int final_rank;</span><br><span class="line">    int local_rank;</span><br><span class="line">&#125;stu[30010],temp;</span><br><span class="line">bool cmp(person a, person b)&#123;</span><br><span class="line">    if(a.score != b.score) return a.score &gt; b.score;</span><br><span class="line">    else return strcmp(a.id, b.id) &lt; 0;</span><br><span class="line">&#125;</span><br><span class="line">int main()&#123;</span><br><span class="line">    int location, n, total = 0;</span><br><span class="line">    scanf(&quot;%d&quot;, &amp;location);</span><br><span class="line">    for (int i = 1; i &lt;= location; i++) &#123;</span><br><span class="line">        scanf(&quot;%d&quot;, &amp;n);</span><br><span class="line">        for (int j = 0; j &lt; n; j++) &#123;</span><br><span class="line">            scanf(&quot;%s%d&quot;, stu[total].id, &amp;stu[total].score);</span><br><span class="line">            stu[total].location = i;</span><br><span class="line">            total++;</span><br><span class="line">        &#125;</span><br><span class="line">        //先按各场地成绩排名</span><br><span class="line">        sort(stu + total - n, stu + total, cmp);</span><br><span class="line">        stu[total - n].local_rank = 1;//确认第一名</span><br><span class="line">        for (int i = 1; i &lt;= n; i++) &#123;</span><br><span class="line">            if (stu[total - n + i].score == stu[total - n + i - 1].score) stu[total - n +i].local_rank = stu[total - n + i - 1].local_rank;</span><br><span class="line">            else stu[total - n + i].local_rank = i + 1;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    //再按成绩排名</span><br><span class="line">    sort(stu, stu + total, cmp);</span><br><span class="line">    stu[0].final_rank = 1;//确认第一名</span><br><span class="line">    for (int i = 1; i &lt;= total; i++) &#123;</span><br><span class="line">        if (stu[i].score == stu[i - 1].score) stu[i].final_rank = stu[i - 1].final_rank;</span><br><span class="line">        else stu[i].final_rank = i + 1;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    printf(&quot;%d\n&quot;, total);</span><br><span class="line">    for (int i = 0; i &lt; total; i++) &#123;</span><br><span class="line">        printf(&quot;%s %d %d %d\n&quot;, stu[i].id, stu[i].final_rank, stu[i].location, stu[i].local_rank);</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    return 0;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.hemisu.com/2017/02/08/109/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="何米酥">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="何米酥`s Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/02/08/109/" itemprop="url">PAT A1016</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-02-08T16:16:04+00:00">
                2017-02-08
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/algorithm-PAT/" itemprop="url" rel="index">
                    <span itemprop="name">algorithm - PAT</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>A long-distance telephone company charges its customers by the following rules:</p>
<p>Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is made. When a customer starts connecting a long-distance call, the time will be recorded, and so will be the time when the customer hangs up the phone. Every calendar month, a bill is sent to the customer for each minute called (at a rate determined by the time of day). Your job is to prepare the bills for each month, given a set of phone call records.</p>
<p>Input Specification:</p>
<p>Each input file contains one test case. Each case has two parts: the rate structure, and the phone call records.</p>
<p>The rate structure consists of a line with 24 non-negative integers denoting the toll (cents/minute) from 00:00 - 01:00, the toll from 01:00 - 02:00, and so on for each hour in the day.</p>
<p>The next line contains a positive number N (&lt;= 1000), followed by N lines of records. Each phone call record consists of the name of the customer (string of up to 20 characters without space), the time and date (mm:dd:hh:mm), and the word “on-line” or “off-line”.</p>
<p>For each test case, all dates will be within a single month. Each “on-line” record is paired with the chronologically next record for the same customer provided it is an “off-line” record. Any “on-line” records that are not paired with an “off-line” record are ignored, as are “off-line” records not paired with an “on-line” record. It is guaranteed that at least one call is well paired in the input. You may assume that no two records for the same customer have the same time. Times are recorded using a 24-hour clock.</p>
<p>Output Specification:</p>
<p>For each test case, you must print a phone bill for each customer.</p>
<p>Bills must be printed in alphabetical order of customers’ names. For each customer, first print in a line the name of the customer and the month of the bill in the format shown by the sample. Then for each time period of a call, print in one line the beginning and ending time and date (dd:hh:mm), the lasting time (in minute) and the charge of the call. The calls must be listed in chronological order. Finally, print the total charge for the month in the format shown by the sample.</p>
<p>Sample Input:<br>10 10 10 10 10 10 20 20 20 15 15 15 15 15 15 15 20 30 20 15 15 10 10 10<br>10<br>CYLL 01:01:06:01 on-line<br>CYLL 01:28:16:05 off-line<br>CYJJ 01:01:07:00 off-line<br>CYLL 01:01:08:03 off-line<br>CYJJ 01:01:05:59 on-line<br>aaa 01:01:01:03 on-line<br>aaa 01:02:00:01 on-line<br>CYLL 01:28:15:41 on-line<br>aaa 01:05:02:24 on-line<br>aaa 01:04:23:59 off-line<br>Sample Output:<br>CYJJ 01<br>01:05:59 01:07:00 61 $12.10<br>Total amount: $12.10<br>CYLL 01<br>01:06:01 01:08:03 122 $24.40<br>28:15:41 28:16:05 24 $3.85<br>Total amount: $28.25<br>aaa 01<br>02:00:01 04:23:59 4318 $638.80<br>Total amount: $638.80<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br></pre></td><td class="code"><pre><span class="line">#include &quot;stdio.h&quot;</span><br><span class="line">//#include &quot;math.h&quot;</span><br><span class="line">#include &quot;string.h&quot;</span><br><span class="line">#include &quot;algorithm&quot;</span><br><span class="line">using namespace std;</span><br><span class="line">const int maxn = 1010;</span><br><span class="line">int toll[25] = &#123;0&#125;;//资费</span><br><span class="line">struct Record&#123;</span><br><span class="line">    char name[25];</span><br><span class="line">    int month, d, h, m;</span><br><span class="line">    bool status;</span><br><span class="line">&#125;rec[maxn], temp;</span><br><span class="line">bool cmp(Record a,Record b)&#123;</span><br><span class="line">    int s = strcmp(a.name, b.name);</span><br><span class="line">    if (s != 0) return s &lt; 0;</span><br><span class="line">    else if (a.month != b.month) return a.month &lt; b.month;</span><br><span class="line">    else if (a.d != b.d) return a.d &lt; b.d;</span><br><span class="line">    else if (a.h != b.h) return a.h &lt; b.h;</span><br><span class="line">    else return a.m &lt; b.m;</span><br><span class="line">&#125;</span><br><span class="line">void get_ans(int on, int off, int&amp; time, int&amp; money)&#123;</span><br><span class="line">    temp = rec[on];</span><br><span class="line">    while (temp.d &lt; rec[off].d || temp.h &lt; rec[off].h || temp.m &lt; rec[off].m) &#123;</span><br><span class="line">        time++;</span><br><span class="line">        money += toll[temp.h];</span><br><span class="line">        temp.m++;</span><br><span class="line">        if (temp.m &gt;= 60) &#123;</span><br><span class="line">            temp.m = 0;</span><br><span class="line">            temp.h++;</span><br><span class="line">        &#125;</span><br><span class="line">        if (temp.h &gt;= 24) &#123;</span><br><span class="line">            temp.h = 0;</span><br><span class="line">            temp.d++;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">int main()&#123;</span><br><span class="line">    for (int i = 0; i &lt; 24; i++) &#123;</span><br><span class="line">        scanf(&quot;%d&quot;, &amp;toll[i]);</span><br><span class="line">    &#125;</span><br><span class="line">    int n;</span><br><span class="line">    scanf(&quot;%d&quot;, &amp;n);</span><br><span class="line">    char line[10];</span><br><span class="line">    for (int i = 0; i &lt; n; i++) &#123;</span><br><span class="line">        scanf(&quot;%s&quot;, rec[i].name);</span><br><span class="line">        scanf(&quot;%d:%d:%d:%d&quot;, &amp;rec[i].month, &amp;rec[i].d, &amp;rec[i].h, &amp;rec[i].m);</span><br><span class="line">        scanf(&quot;%s&quot;, line);</span><br><span class="line">        if (strcmp(line, &quot;on-line&quot;) == 0) &#123;</span><br><span class="line">            rec[i].status = true;</span><br><span class="line">        &#125;else&#123;</span><br><span class="line">            rec[i].status = false;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    sort(rec, rec + n, cmp);</span><br><span class="line">    int on = 0, off, next;</span><br><span class="line">    while (on &lt; n) &#123;</span><br><span class="line">        int needPrint = 0;//是否需要输出 1表示找到on 2表示找到off</span><br><span class="line">        next = on;</span><br><span class="line">        while (next &lt; n &amp;&amp; strcmp(rec[next].name, rec[on].name) == 0) &#123;</span><br><span class="line">            if (needPrint == 0 &amp;&amp; rec[next].status == true) &#123;</span><br><span class="line">                needPrint = 1;</span><br><span class="line">            &#125;else if (needPrint == 1 &amp;&amp; rec[next].status == false)&#123;</span><br><span class="line">                needPrint = 2;</span><br><span class="line">            &#125;</span><br><span class="line">            next++;</span><br><span class="line">        &#125;</span><br><span class="line">        if (needPrint &lt; 2) &#123;//没有找到配对的on-off</span><br><span class="line">            on = next;</span><br><span class="line">            continue;</span><br><span class="line">        &#125;</span><br><span class="line">        int AllMoney = 0;</span><br><span class="line">        printf(&quot;%s %02d\n&quot;, rec[on].name, rec[on].month);</span><br><span class="line">        while (on &lt; next) &#123;</span><br><span class="line">            while (on &lt; next - 1</span><br><span class="line">                   &amp;&amp; !(rec[on].status == true &amp;&amp; rec[on + 1].status == false)</span><br><span class="line">                   ) &#123;</span><br><span class="line">                on++;</span><br><span class="line">            &#125;</span><br><span class="line">            off = on + 1;</span><br><span class="line">            if (off == next) &#123;</span><br><span class="line">                on = next;</span><br><span class="line">                break;</span><br><span class="line">            &#125;</span><br><span class="line">            printf(&quot;%02d:%02d:%02d &quot;, rec[on].d, rec[on].h, rec[on].m);</span><br><span class="line">            printf(&quot;%02d:%02d:%02d &quot;, rec[off].d, rec[off].h, rec[off].m);</span><br><span class="line">            int time = 0, money = 0;</span><br><span class="line">            get_ans(on, off, time, money);</span><br><span class="line">            AllMoney += money;</span><br><span class="line">            printf(&quot;%d $%.2f\n&quot;, time, money / 100.0);</span><br><span class="line">            on = off + 1;//完成一个配对，从off+1开始下一对</span><br><span class="line">        &#125;</span><br><span class="line">        printf(&quot;Total amount: $%.2f\n&quot;, AllMoney / 100.0);</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    return 0;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.hemisu.com/2017/02/08/107/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="何米酥">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="何米酥`s Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/02/08/107/" itemprop="url">PAT A1012</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-02-08T14:03:55+00:00">
                2017-02-08
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/algorithm-PAT/" itemprop="url" rel="index">
                    <span itemprop="name">algorithm - PAT</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C - C Programming Language, M - Mathematics (Calculus or Linear Algebra), and E - English. At the mean time, we encourage students by emphasizing on their best ranks – that is, among the four ranks with respect to the three courses and the average grade, we print the best rank for each student.</p>
<p>For example, The grades of C, M, E and A - Average of 4 students are given as the following:</p>
<p>StudentID  C  M  E  A<br>310101     98 85 88 90<br>310102     70 95 88 84<br>310103     82 87 94 88<br>310104     91 91 91 91<br>Then the best ranks for all the students are No.1 since the 1st one has done the best in C Programming Language, while the 2nd one in Mathematics, the 3rd one in English, and the last one in average.</p>
<p>Input</p>
<p>Each input file contains one test case. Each case starts with a line containing 2 numbers N and M (&lt;=2000), which are the total number of students, and the number of students who would check their ranks, respectively. Then N lines follow, each contains a student ID which is a string of 6 digits, followed by the three integer grades (in the range of [0, 100]) of that student in the order of C, M and E. Then there are M lines, each containing a student ID.</p>
<p>Output</p>
<p>For each of the M students, print in one line the best rank for him/her, and the symbol of the corresponding rank, separated by a space.</p>
<p>The priorities of the ranking methods are ordered as A &gt; C &gt; M &gt; E. Hence if there are two or more ways for a student to obtain the same best rank, output the one with the highest priority.</p>
<p>If a student is not on the grading list, simply output “N/A”.</p>
<p>Sample Input<br>5 6<br>310101 98 85 88<br>310102 70 95 88<br>310103 82 87 94<br>310104 91 91 91<br>310105 85 90 90<br>310101<br>310102<br>310103<br>310104<br>310105<br>999999<br>Sample Output<br>1 C<br>1 M<br>1 E<br>1 A<br>3 A<br>N/A<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br></pre></td><td class="code"><pre><span class="line">#include &quot;stdio.h&quot;</span><br><span class="line">//#include &quot;math.h&quot;</span><br><span class="line">#include &quot;string.h&quot;</span><br><span class="line">#include &quot;algorithm&quot;</span><br><span class="line">using namespace std;</span><br><span class="line">struct person&#123;</span><br><span class="line">    int id;</span><br><span class="line">    int grade[4];//grade[0]:A grade[1]:C grade[2]:M grade[3]:E</span><br><span class="line">&#125;stu[2010];</span><br><span class="line"></span><br><span class="line">char course[4] = &#123;&apos;A&apos;, &apos;C&apos;, &apos;M&apos;, &apos;E&apos;&#125;;</span><br><span class="line">int Rank[1000000][4] = &#123;0&#125;;</span><br><span class="line">int now;//cmp函数中使用，表示当前按now号分数排序stu数组</span><br><span class="line"></span><br><span class="line">bool cmp(person a, person b)&#123;</span><br><span class="line">    return a.grade[now] &gt; b.grade[now];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">int main()&#123;</span><br><span class="line">    int n, m;</span><br><span class="line">    scanf(&quot;%d%d&quot;, &amp;n, &amp;m);</span><br><span class="line">    //读入分数</span><br><span class="line">    for (int i = 0; i &lt; n; i++) &#123;</span><br><span class="line">        scanf(&quot;%d%d%d%d&quot;, &amp;stu[i].id, &amp;stu[i].grade[1], &amp;stu[i].grade[2], &amp;stu[i].grade[3]);</span><br><span class="line">        stu[i].grade[0] = stu[i].grade[1] + stu[i].grade[2] + stu[i].grade[3];</span><br><span class="line">    &#125;</span><br><span class="line">    for (now = 0; now &lt;=3; now++) &#123;</span><br><span class="line">        sort(stu, stu + n, cmp);//按照A C M E 分别排序</span><br><span class="line">        Rank[stu[0].id][now] = 1;</span><br><span class="line">        for (int i = 1; i &lt; n; i++) &#123;</span><br><span class="line">            //若与前一位考生分数相同</span><br><span class="line">            if(stu[i].grade[now] == stu[i - 1].grade[now])&#123;</span><br><span class="line">                Rank[stu[i].id][now] = Rank[stu[i - 1].id][now];</span><br><span class="line">            &#125;else&#123;</span><br><span class="line">                Rank[stu[i].id][now] = i + 1;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    int query;</span><br><span class="line">    for (int i = 0; i &lt; m; i++) &#123;</span><br><span class="line">        scanf(&quot;%d&quot;, &amp;query);</span><br><span class="line">        if (Rank[query][0] == 0) &#123;</span><br><span class="line">            printf(&quot;N/A\n&quot;);</span><br><span class="line">        &#125;else&#123;</span><br><span class="line">            int k = 0;</span><br><span class="line">            for (int j = 0; j &lt; 4; j++) &#123;</span><br><span class="line">                if(Rank[query][j] &lt; Rank[query][k]) k = j;</span><br><span class="line">            &#125;</span><br><span class="line">            printf(&quot;%d %c\n&quot;,Rank[query][k] ,course[k]);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    return 0;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>收获：<br>优先级为A&gt;C&gt;M&gt;E,所以考虑设置数组时就按这个顺序：<br>即0对应A,1对应C,2对应M,3对应E；<br>并且编写CMP函数的时候可以按照这个编号来排序。<br>另外，本题没有明示平均分是否需要取整以及取整方式，并且没有输出平均分，可以考虑用三门课总分代替，不用除以3。</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.hemisu.com/2017/02/08/105/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="何米酥">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="何米酥`s Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/02/08/105/" itemprop="url">PAT B1015/A1062</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-02-08T11:27:45+00:00">
                2017-02-08
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/algorithm-PAT/" itemprop="url" rel="index">
                    <span itemprop="name">algorithm - PAT</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>宋代史学家司马光在《资治通鉴》中有一段著名的“德才论”：“是故才德全尽谓之圣人，才德兼亡谓之愚人，德胜才谓之君子，才胜德谓之小人。凡取人之术，苟不得圣人，君子而与之，与其得小人，不若得愚人。”</p>
<p>现给出一批考生的德才分数，请根据司马光的理论给出录取排名。</p>
<p>输入格式：</p>
<p>输入第1行给出3个正整数，分别为：N（&lt;=105），即考生总数；L（&gt;=60），为录取最低分数线，即德分和才分均不低于L的考生才有资格被考虑录取；H（&lt;100），为优先录取线——德分和才分均不低于此线的被定义为“才德全尽”，此类考生按德才总分从高到低排序；才分不到但德分到线的一类考生属于“德胜才”，也按总分排序，但排在第一类考生之后；德才分均低于H，但是德分不低于才分的考生属于“才德兼亡”但尚有“德胜才”者，按总分排序，但排在第二类考生之后；其他达到最低线L的考生也按总分排序，但排在第三类考生之后。</p>
<p>随后N行，每行给出一位考生的信息，包括：准考证号、德分、才分，其中准考证号为8位整数，德才分为区间[0, 100]内的整数。数字间以空格分隔。</p>
<p>输出格式：</p>
<p>输出第1行首先给出达到最低分数线的考生人数M，随后M行，每行按照输入格式输出一位考生的信息，考生按输入中说明的规则从高到低排序。当某类考生中有多人总分相同时，按其德分降序排列；若德分也并列，则按准考证号的升序输出。</p>
<p>输入样例：<br>14 60 80<br>10000001 64 90<br>10000002 90 60<br>10000011 85 80<br>10000003 85 80<br>10000004 80 85<br>10000005 82 77<br>10000006 83 76<br>10000007 90 78<br>10000008 75 79<br>10000009 59 90<br>10000010 88 45<br>10000012 80 100<br>10000013 90 99<br>10000014 66 60<br>输出样例：<br>12<br>10000013 90 99<br>10000012 80 100<br>10000003 85 80<br>10000011 85 80<br>10000004 80 85<br>10000007 90 78<br>10000006 83 76<br>10000005 82 77<br>10000002 90 60<br>10000014 66 60<br>10000008 75 79<br>10000001 64 90</p>
<p>About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about people’s talent and virtue. According to his theory, a man being outstanding in both talent and virtue must be a “sage（圣人）”; being less excellent but with one’s virtue outweighs talent can be called a “nobleman（君子）”; being good in neither is a “fool man（愚人）”; yet a fool man is better than a “small man（小人）” who prefers talent than virtue.</p>
<p>Now given the grades of talent and virtue of a group of people, you are supposed to rank them according to Sima Guang’s theory.</p>
<p>Input Specification:</p>
<p>Each input file contains one test case. Each case first gives 3 positive integers in a line: N (&lt;=105), the total number of people to be ranked; L (&gt;=60), the lower bound of the qualified grades – that is, only the ones whose grades of talent and virtue are both not below this line will be ranked; and H (&lt;100), the higher line of qualification – that is, those with both grades not below this line are considered as the “sages”, and will be ranked in non-increasing order according to their total grades. Those with talent grades below H but virtue grades not are cosidered as the “noblemen”, and are also ranked in non-increasing order according to their total grades, but they are listed after the “sages”. Those with both grades below H, but with virtue not lower than talent are considered as the “fool men”. They are ranked in the same way but after the “noblemen”. The rest of people whose grades both pass the L line are ranked after the “fool men”.</p>
<p>Then N lines follow, each gives the information of a person in the format:</p>
<p>ID_Number Virtue_Grade Talent_Grade<br>where ID_Number is an 8-digit number, and both grades are integers in [0, 100]. All the numbers are separated by a space.<br>Output Specification:</p>
<p>The first line of output must give M (&lt;=N), the total number of people that are actually ranked. Then M lines follow, each gives the information of a person in the same format as the input, according to the ranking rules. If there is a tie of the total grade, they must be ranked with respect to their virtue grades in non-increasing order. If there is still a tie, then output in increasing order of their ID’s.</p>
<p>Sample Input:<br>14 60 80<br>10000001 64 90<br>10000002 90 60<br>10000011 85 80<br>10000003 85 80<br>10000004 80 85<br>10000005 82 77<br>10000006 83 76<br>10000007 90 78<br>10000008 75 79<br>10000009 59 90<br>10000010 88 45<br>10000012 80 100<br>10000013 90 99<br>10000014 66 60<br>Sample Output:<br>12<br>10000013 90 99<br>10000012 80 100<br>10000003 85 80<br>10000011 85 80<br>10000004 80 85<br>10000007 90 78<br>10000006 83 76<br>10000005 82 77<br>10000002 90 60<br>10000014 66 60<br>10000008 75 79<br>10000001 64 90<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line">#include &quot;stdio.h&quot;</span><br><span class="line">//#include &quot;math.h&quot;</span><br><span class="line">#include &quot;string.h&quot;</span><br><span class="line">#include &quot;algorithm&quot;</span><br><span class="line">using namespace std;</span><br><span class="line">struct person&#123;</span><br><span class="line">    char id[15];</span><br><span class="line">    int virtue, talent, sum;</span><br><span class="line">    int flag;//类别排序 1：圣人 sage 2：君子 nobleman 3：愚人 foolman 4：小人 smallman 5：不及格</span><br><span class="line">&#125;people[100010];</span><br><span class="line">bool cmp (person a, person b)&#123;</span><br><span class="line">    if (a.flag != b.flag) return a.flag &lt; b.flag;</span><br><span class="line">    else if (a.sum != b.sum) return a.sum &gt; b.sum;</span><br><span class="line">    else if (a.virtue != b.virtue) return a.virtue &gt; b.virtue;</span><br><span class="line">    else return strcmp(a.id, b.id) &lt; 0;</span><br><span class="line">&#125;</span><br><span class="line">int main()&#123;</span><br><span class="line">    int n, l, h;</span><br><span class="line">    scanf(&quot;%d%d%d&quot;, &amp;n, &amp;l, &amp;h);</span><br><span class="line">    int m = n;//及格人数</span><br><span class="line">    for (int i = 0 ; i &lt; n; i++) &#123;</span><br><span class="line">        scanf(&quot;%s%d%d&quot;, people[i].id, &amp;people[i].virtue, &amp;people[i].talent);</span><br><span class="line">        people[i].sum = people[i].virtue + people[i].talent;</span><br><span class="line">        if(people[i].virtue &lt; l || people[i].talent &lt; l) &#123;people[i].flag = 5;m--;&#125;</span><br><span class="line">        else if (people[i].talent &gt;= h &amp;&amp; people[i].virtue &gt;= h) people[i].flag = 1;</span><br><span class="line">        //those with both grades not below this line are considered as the &quot;sages&quot;</span><br><span class="line">        else if (people[i].virtue &gt;= h &amp;&amp; people[i].talent &gt;= l &amp;&amp; people[i].talent &lt; h) people[i].flag = 2;</span><br><span class="line">        //Those with talent grades below H but virtue grades not are cosidered as the &quot;noblemen&quot;</span><br><span class="line">        else if (people[i].virtue &gt;= people[i].talent) people[i].flag = 3;</span><br><span class="line">        //Those with both grades below H, but with virtue not lower than talent are considered as the &quot;fool men&quot;.</span><br><span class="line">        else people[i].flag = 4;</span><br><span class="line">    &#125;</span><br><span class="line">    sort(people, people + n, cmp);</span><br><span class="line">    printf(&quot;%d\n&quot;, m);</span><br><span class="line">    for (int i = 0; i &lt; m; i++) &#123;</span><br><span class="line">        printf(&quot;%s %d %d\n&quot;, people[i].id, people[i].virtue, people[i].talent);</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    return 0;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>收获：<br>其中准考证号为8位整数,如果用int 或者long long都会显示段错误，所以得使用char来保存id</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.hemisu.com/2017/02/08/104/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="何米酥">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="何米酥`s Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/02/08/104/" itemprop="url">PAT B1040/A1093</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-02-08T10:42:00+00:00">
                2017-02-08
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/algorithm-PAT/" itemprop="url" rel="index">
                    <span itemprop="name">algorithm - PAT</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>字符串APPAPT中包含了两个单词“PAT”，其中第一个PAT是第2位(P),第4位(A),第6位(T)；第二个PAT是第3位(P),第4位(A),第6位(T)。</p>
<p>现给定字符串，问一共可以形成多少个PAT？</p>
<p>输入格式：</p>
<p>输入只有一行，包含一个字符串，长度不超过105，只包含P、A、T三种字母。</p>
<p>输出格式：</p>
<p>在一行中输出给定字符串中包含多少个PAT。由于结果可能比较大，只输出对1000000007取余数的结果。</p>
<p>输入样例：<br>APPAPT<br>输出样例：<br>2</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">#include &quot;stdio.h&quot;</span><br><span class="line">//#include &quot;math.h&quot;</span><br><span class="line">#include &quot;string.h&quot;</span><br><span class="line">//#include &quot;algorithm&quot;</span><br><span class="line">//using namespace std;</span><br><span class="line">const int MAXN = 100010;</span><br><span class="line">const int Mod = 1000000007;</span><br><span class="line">char str[MAXN];</span><br><span class="line">int leftNumP[MAXN] = &#123;0&#125;;//写成了char型</span><br><span class="line">int main()&#123;</span><br><span class="line">    gets(str);</span><br><span class="line">    int len = (int)strlen(str);</span><br><span class="line">    for (int i = 0 ; i &lt; len; i++) &#123;</span><br><span class="line">        if (i &gt; 0) &#123;</span><br><span class="line">            leftNumP[i] = leftNumP[i - 1];</span><br><span class="line">        &#125;</span><br><span class="line">        if (str[i] == &apos;P&apos;) &#123;</span><br><span class="line">            leftNumP[i]++;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    int ans = 0,rightNumT = 0;</span><br><span class="line">    for (int i = len - 1; i &gt;= 0; i--) &#123;</span><br><span class="line">        if (str[i] == &apos;T&apos;) &#123;</span><br><span class="line">            rightNumT++;</span><br><span class="line">        &#125;else if (str[i] == &apos;A&apos;)&#123;</span><br><span class="line">            ans = (ans + leftNumP[i] * rightNumT ) % Mod;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    printf(&quot;%d&quot;, ans);</span><br><span class="line">    </span><br><span class="line">    return 0;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>算法笔记上的答案最后两个测试点通不过，原因不明<br>20：13分改：抄代码不认真 把leftNumP定义成了char型。改回int就好了</p>
<p>附上百度来的答案</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">#include &lt;stdio.h&gt;  </span><br><span class="line">#include &lt;string.h&gt;  </span><br><span class="line">int main() &#123;  </span><br><span class="line">    char str[100001];  </span><br><span class="line">    gets(str);  </span><br><span class="line">    int numT = 0;  </span><br><span class="line">    int numAT = 0;  </span><br><span class="line">    int numPAT = 0;  </span><br><span class="line">    for(int i = strlen(str) - 1; i &gt;= 0; --i) &#123;               //从字符串后面向前遍历  </span><br><span class="line">        if(str[i] == &apos;T&apos;)                    //碰到T，记录该T后面T的总个数（包括这个T）  </span><br><span class="line">            ++numT;  </span><br><span class="line">        else if(str[i] == &apos;A&apos;)                   //碰到A，记录该A后面AT组合的总个数；其中包括之前统计的A后面AT的总个数加上这个A与后面全部T组合的个数（  </span><br><span class="line">            numAT = (numAT + numT) % 1000000007;  </span><br><span class="line">        else &#123;                           //碰到P，记录该P后面PAT组合的总个数；同理  </span><br><span class="line">            numPAT = (numPAT + numAT) % 1000000007;  </span><br><span class="line">        &#125;  </span><br><span class="line">    &#125;  </span><br><span class="line">    printf(&quot;%d&quot;, numPAT);  </span><br><span class="line">  </span><br><span class="line">  </span><br><span class="line">    return 0;  </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.hemisu.com/2017/02/07/103/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="何米酥">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="何米酥`s Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/02/07/103/" itemprop="url">PAT A1082</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-02-07T23:54:51+00:00">
                2017-02-07
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/algorithm-PAT/" itemprop="url" rel="index">
                    <span itemprop="name">algorithm - PAT</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>GGiven an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese way. Output “Fu” first if it is negative. For example, -123456789 is read as “Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu”. Note: zero (“ling”) must be handled correctly according to the Chinese tradition. For example, 100800 is “yi Shi Wan ling ba Bai”.</p>
<p>Input Specification:</p>
<p>Each input file contains one test case, which gives an integer with no more than 9 digits.</p>
<p>Output Specification:</p>
<p>For each test case, print in a line the Chinese way of reading the number. The characters are separated by a space and there must be no extra space at the end of the line.</p>
<p>Sample Input 1:<br>-123456789<br>Sample Output 1:<br>Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu<br>Sample Input 2:<br>100800<br>Sample Output 2:<br>yi Shi Wan ling ba Bai</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><span class="line">#include &lt;stdio.h&gt;</span><br><span class="line">#include &lt;cstring&gt;</span><br><span class="line">char num[10][5] = &#123;&quot;ling&quot;, &quot;yi&quot;, &quot;er&quot;, &quot;san&quot;, &quot;si&quot;, &quot;wu&quot;, &quot;liu&quot;, &quot;qi&quot;, &quot;ba&quot;, &quot;jiu&quot;&#125;;</span><br><span class="line">char wei[5][5] = &#123;&quot;Shi&quot;, &quot;Bai&quot;, &quot;Qian&quot;, &quot;Wan&quot;, &quot;Yi&quot;&#125;;</span><br><span class="line">  int main()&#123;</span><br><span class="line">  	char str[15];</span><br><span class="line">    	gets(str);</span><br><span class="line">    	int len = strlen(str);</span><br><span class="line">    	int left = 0, right = len - 1;</span><br><span class="line">    if(str[0] == &apos;-&apos;) &#123;</span><br><span class="line">    	printf(&quot;Fu&quot;);</span><br><span class="line">      	left++;</span><br><span class="line">    &#125;</span><br><span class="line">    while(left + 4 &lt;= right)&#123;</span><br><span class="line">    	right -= 4;</span><br><span class="line">    &#125;</span><br><span class="line">    while(left &lt; len)&#123;</span><br><span class="line">    	bool flag = false;</span><br><span class="line">      	bool isPrint = false;</span><br><span class="line">      while(left &lt;= right)&#123;</span><br><span class="line">      	if(left &gt; 0 &amp;&amp; str[left] == &apos;0&apos;)&#123;</span><br><span class="line">          flag = true;</span><br><span class="line">        &#125; else &#123;</span><br><span class="line">          if(flag == true)&#123;</span><br><span class="line">            printf(&quot; ling&quot;);</span><br><span class="line">            flag = false;</span><br><span class="line">        </span><br><span class="line">          &#125;</span><br><span class="line">          if(left &gt; 0) printf(&quot; &quot;);</span><br><span class="line">          printf(&quot;%s&quot;, num[str[left] - &apos;0&apos;]);</span><br><span class="line">          isPrint = true;</span><br><span class="line">          if(left != right)&#123;</span><br><span class="line">            printf(&quot; %s&quot;, wei[right - left -1]);</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        left++;</span><br><span class="line">      &#125;</span><br><span class="line">      if(isPrint== true &amp;&amp; right != len-1)&#123;</span><br><span class="line">        printf(&quot; %s&quot;, wei[(len - 1 - right) / 4 +2]);</span><br><span class="line">      &#125;</span><br><span class="line">      right += 4;</span><br><span class="line">    &#125;</span><br><span class="line">    return 0;</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>
<p>这题抄的笔记 还得看看。。mark一个</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.hemisu.com/2017/02/07/102/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="何米酥">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="何米酥`s Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/02/07/102/" itemprop="url">PAT A1082</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-02-07T01:46:04+00:00">
                2017-02-07
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/algorithm-PAT/" itemprop="url" rel="index">
                    <span itemprop="name">algorithm - PAT</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese way. Output “Fu” first if it is negative. For example, -123456789 is read as “Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu”. Note: zero (“ling”) must be handled correctly according to the Chinese tradition. For example, 100800 is “yi Shi Wan ling ba Bai”.</p>
<p>Input Specification:</p>
<p>Each input file contains one test case, which gives an integer with no more than 9 digits.</p>
<p>Output Specification:</p>
<p>For each test case, print in a line the Chinese way of reading the number. The characters are separated by a space and there must be no extra space at the end of the line.</p>
<p>Sample Input 1:<br>-123456789<br>Sample Output 1:<br>Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu<br>Sample Input 2:<br>100800<br>Sample Output 2:<br>yi Shi Wan ling ba Bai</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.hemisu.com/2017/02/06/101/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="何米酥">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="何米酥`s Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/02/06/101/" itemprop="url">PAT A1077</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-02-06T21:24:10+00:00">
                2017-02-06
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/algorithm-PAT/" itemprop="url" rel="index">
                    <span itemprop="name">algorithm - PAT</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>The Japanese language is notorious for its sentence ending particles. Personal preference of such particles can be considered as a reflection of the speaker’s personality. Such a preference is called “Kuchiguse” and is often exaggerated artistically in Anime and Manga. For example, the artificial sentence ending particle “nyan~” is often used as a stereotype for characters with a cat-like personality:</p>
<p>Itai nyan~ (It hurts, nyan~)<br>Ninjin wa iyada nyan~ (I hate carrots, nyan~)<br>Now given a few lines spoken by the same character, can you find her Kuchiguse?</p>
<p>Input Specification:</p>
<p>Each input file contains one test case. For each case, the first line is an integer N (2&lt;=N&lt;=100). Following are N file lines of 0~256 (inclusive) characters in length, each representing a character’s spoken line. The spoken lines are case sensitive.</p>
<p>Output Specification:</p>
<p>For each test case, print in one line the kuchiguse of the character, i.e., the longest common suffix of all N lines. If there is no such suffix, write “nai”.</p>
<p>Sample Input 1:<br>3<br>Itai nyan~<br>Ninjin wa iyadanyan~<br>uhhh nyan~<br>Sample Output 1:<br>nyan~<br>Sample Input 2:<br>3<br>Itai!<br>Ninjinnwaiyada T_T<br>T_T<br>Sample Output 2:<br>nai</p>
<pre><code>#include &quot;stdio.h&quot;
//#include &quot;math.h&quot;
#include &quot;string.h&quot;
//#include &quot;algorithm&quot;
//using namespace std;
int n, minLen = 256, ans = 0;
char s[100][256];
int main(){
    scanf(&quot;%d&quot;, &amp;n);
    getchar();
    for (int i = 0; i &lt; n; i++) {
        gets(s[i]);
        int len = (int)strlen(s[i]);
        if (len &lt; minLen) {
            minLen = len;
        }
        for (int j = 0; j &lt; len/2; j++) {
            char temp = s[i][j];
            s[i][j] = s[i][len - j -1];
            s[i][len - j - 1] = temp;
        }
    }
    for (int i = 0; i &lt; minLen; i++) {
        char c = s[0][i];
        bool same = true;
        for (int j = 1; j &lt; n; j++) {
            if (c != s[j][i]) {
                same = false;
                break;
            }
        }
        if (same) ans++;
        else break;
    }
    if (ans) {
        for (int i = ans - 1; i &gt;= 0; i--) {
            printf(&quot;%c&quot;, s[0][i]);
        }
    }else{
        printf(&quot;nai&quot;);
    }

    return 0;
}
</code></pre>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.hemisu.com/2017/02/06/100/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="何米酥">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="何米酥`s Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/02/06/100/" itemprop="url">PAT A1035</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-02-06T20:49:00+00:00">
                2017-02-06
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/algorithm-PAT/" itemprop="url" rel="index">
                    <span itemprop="name">algorithm - PAT</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem is that there are always some confusing passwords since it is hard to distinguish 1 (one) from l (L in lowercase), or 0 (zero) from O (o in uppercase). One solution is to replace 1 (one) by @, 0 (zero) by %, l by L, and O by o. Now it is your job to write a program to check the accounts generated by the judge, and to help the juge modify the confusing passwords.</p>
<p>Input Specification:</p>
<p>Each input file contains one test case. Each case contains a positive integer N (&lt;= 1000), followed by N lines of accounts. Each account consists of a user name and a password, both are strings of no more than 10 characters with no space.</p>
<p>Output Specification:</p>
<p>For each test case, first print the number M of accounts that have been modified, then print in the following M lines the modified accounts info, that is, the user names and the corresponding modified passwords. The accounts must be printed in the same order as they are read in. If no account is modified, print in one line “There are N accounts and no account is modified” where N is the total number of accounts. However, if N is one, you must print “There is 1 account and no account is modified” instead.</p>
<p>Sample Input 1:</p>
<p>3<br>Team000002 Rlsp0dfa<br>Team000003 perfectpwd<br>Team000001 R1spOdfa<br>Sample Output 1:<br>2<br>Team000002 RLsp%dfa<br>Team000001 R@spodfa<br>Sample Input 2:<br>1<br>team110 abcdefg332<br>Sample Output 2:<br>There is 1 account and no account is modified<br>Sample Input 3:<br>2<br>team110 abcdefg222<br>team220 abcdefg333<br>Sample Output 3:<br>There are 2 accounts and no account is modified</p>
<pre><code>#include &quot;stdio.h&quot;
//#include &quot;math.h&quot;
#include &quot;string.h&quot;
//#include &quot;algorithm&quot;
//using namespace std;
struct person{
    char name[15];
    char password[15];
    bool ischange;
}T[1005], temp;
void crypt(person&amp; t, int&amp; cnt){//引用型
    int passlen = (int)strlen(t.password);
    for (int i = 0; i &lt; passlen; i++) {
        switch (t.password[i]) {
            case &apos;1&apos;:
                t.password[i] = &apos;@&apos;;
                t.ischange = true;
                break;
            case &apos;0&apos;:
                t.password[i] = &apos;%&apos;;
                t.ischange = true;
                break;
            case &apos;l&apos;:
                t.password[i] = &apos;L&apos;;
                t.ischange = true;
                break;
            case &apos;O&apos;:
                t.password[i] = &apos;o&apos;;
                t.ischange = true;
                break;
            default:
                break;
        }
    }
    if (t.ischange == true) {
        cnt ++;
    }

}
int main(){
    int n,cnt = 0;
    scanf(&quot;%d&quot;, &amp;n);
    for (int i = 0; i &lt; n; i++) {
        scanf(&quot;%s %s&quot;, T[i].name, T[i].password);
        T[i].ischange = false;
    }
    for (int i = 0; i &lt; n; i++) {
        crypt(T[i], cnt);
    }
    if (cnt == 0) {
        if (n == 1){
            printf(&quot;There is %d account and no account is modified&quot;, n);
        }else{
            printf(&quot;There are %d accounts and no account is modified&quot;, n);
        }
    }else{
        printf(&quot;%d\n&quot;, cnt);
        for (int i = 0; i &lt; n; i++) {
            if (T[i].ischange) {
                printf(&quot;%s %s\n&quot;, T[i].name, T[i].password);
            }
        }
    }

    return 0;
}
</code></pre><p>本题类似PAT B1031，但是不能像它那样写，这里要先输出修改过的密码个数<br>所以本题用结构体来记录数据，用ischange来标记密码是否经过修改，并且自定义了一个函数crypt，引用型来修改结构体和计数器。<br>此外，要区分没有修改密码情况下输出的语句单复数is/are。</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
  </section>

  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/page/14/"><i class="fa fa-angle-left"></i></a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/14/">14</a><span class="page-number current">15</span><a class="page-number" href="/page/16/">16</a><span class="space">&hellip;</span><a class="page-number" href="/page/21/">21</a><a class="extend next" rel="next" href="/page/16/"><i class="fa fa-angle-right"></i></a>
  </nav>



          </div>
          


          

        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/images/avatar.jpg" alt="何米酥">
            
              <p class="site-author-name" itemprop="name">何米酥</p>
              <p class="site-description motion-element" itemprop="description">Just do...</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">202</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">8</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">78</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/hemisu" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://www.zhihu.com/people/hemisu" target="_blank" title="知乎">
                      
                        <i class="fa fa-fw fa-globe"></i>知乎</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      

      
        <div class="back-to-top">
          <i class="fa fa-arrow-up"></i>
          
            <span id="scrollpercent"><span>0</span>%</span>
          
        </div>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2015 &mdash; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">何米酥</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  

  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
